<template>
	<div id="deviceuserlist" class="same-change-oldstyle">
		<div class="same-head-box">
			<div class="saem-seat-box">
				<div class="saem-seat-left">
					<span>当前位置：</span>
					<el-breadcrumb separator-class="el-icon-arrow-right">
						<el-breadcrumb-item>设备中心</el-breadcrumb-item>
						<el-breadcrumb-item :to="{ path: '/devicelist' }">设备管理</el-breadcrumb-item>
						<el-breadcrumb-item>设备用户统计</el-breadcrumb-item>
					</el-breadcrumb>
				</div>
				<div class="saem-seat-right">
					<button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
					<button class="same-search-btns" @click="returnBack">返回</button>
				</div>
			</div>
			<div class="same-search-box">
				<div class="same-search-left">
					<div class="same-left-one">
						<span class="same-search-span same-search-fisrt">消费时间:</span>
						<el-date-picker style="width:140px" v-model="start_time" type="date" size="medium" value-format="yyyy-MM-dd"
							placeholder="开始时间"></el-date-picker>
						<div class="same-interval">至</div>
						<el-date-picker style="width:140px" v-model="end_time" type="date" size="medium" value-format="yyyy-MM-dd"
							placeholder="结束时间"></el-date-picker>
					</div>
					<div class="same-left-one">
						<span class="same-search-span">用户昵称:</span>
						<el-input size="medium" v-model="name" placeholder="请输入用户昵称" style="width: 160px;"></el-input>
					</div>
					<div class="same-left-one">
						<span class="same-search-span">用户电话:</span>
						<el-input size="medium" v-model="tel" type="number" placeholder="请输入手机号" style="width: 160px;"></el-input>
					</div>
					<div class="same-left-one">
						<el-button type="primary" size="medium" @click="serach()">搜索</el-button>
						<el-button type="info" size="medium" @click="reset()">重置</el-button>
					</div>
				</div>
				<div class="same-search-right"></div>
			</div>
		</div>

		<div class="same-table-box">
			<h4 class="same-title-box">设备用户统计</h4>
			<div class="table_box">

				<div class="common-table-outer">
					<el-table class="common-table" v-loading="loading" header-cell-class-name="common-table-header-cell"
						:data="tableData" stripe>
						<el-table-column align="center" prop="user_name"  label="用户昵称">
						</el-table-column>
						<el-table-column align="center" prop="tel" label="电话">
						</el-table-column>
						<el-table-column align="center" prop="order_count" label="订单数量">
						</el-table-column>
						<el-table-column align="center"  label="总支付金额">
							<template slot-scope="scope">
								{{ scope.row.order_money|filterNumber }}
							</template>
						</el-table-column>

						<el-table-column align="center" prop="pay_time" label="最后消费时间">
						</el-table-column>

						<el-table-column align="center" prop="pay_type" label="用户类型">
						</el-table-column>

				
						<template slot="empty" v-if="isLoad">
							<div class="new-no-data-show">
								<img src="../../assets/images/no-data.png" alt="">
								<div>暂无相关数据</div>
							</div>
						</template>
					</el-table>
	
					<div class="same-page-inShow" v-if="tableData.length > 0 && isLoad">
						<!--//  分页-->
						<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page.sync="pageNo" :page-sizes="pageSizesList" :page-size="pageSize"
							layout="total, prev, pager, next, jumper, sizes" :total="totalDataNumber"></el-pagination>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import { regionDataPlus } from 'element-china-area-data';
	export default {
		name: 'deviceuserlist',
		data: function () {
			return {
				pageNo: 1,
				pageSize: 15,
				pageSizesList: [15, 30, 40, 50],
				tableData: [], // 返回的结果集合
				totalDataNumber: 0, // 数据的总数,-----
				time: '',
				state: this.$route.query.stat_es == 2 ? 2 : '',
				notice: '',
				options: regionDataPlus,
				address: [],
				start_time: '',
				end_time: '',
				equipment_number: '',
				name: '',
				tel: '',
				loading: true, //加载动画
				isLoad: false,
				userAgent: ''
			};
		},
		// 初始化执行
		created: function () {
			var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
			this.userAgent = userAgent;
			var that = this;
			if (locache.get('deviceListPage') != null) {
				that.pageNo = locache.get('deviceListPage');
			}
			if (locache.get('deviceListPageSize') != null) {
				that.pageSize = locache.get('deviceListPageSize');
			}
			var page = that.pageNo; // 当前页
			var pageSize = that.pageSize; // 每页条数
			that.equipment_number = this.$route.query.equipment_number; // 接收设备编号
			that.equipment(page, pageSize); // 获取设备列表数据
		},
		inject: [
			'reload'
		],
		methods: {
			RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
			},
			//返回
			returnBack() {
				this.$router.back(-1);
			},
			handleChange(value) { },
			//编辑
			edit: function (id) {
				this.$router.push({ path: '/edit', query: { id: id } });
			},
			//更多信息
			more: function (val, id) {
				this.$router.push({ path: '/moreinformation', query: { equipment_number: val, id: id } });
			},

			// 每页
			handleSizeChange(val) {
				var that = this;
				that.pageNo = 1;
				locache.set('deviceListPageSize', val);
				that.pageSize = val; // 当前每页显示条数
				that.equipment(that.pageNo, val); // 获取设备列表数据
			},
			// 分页
			handleCurrentChange(val) {
				var that = this;
				var pageSize = that.pageSize; // 每页条数
				that.pageNo = val;
				locache.set('deviceListPage', val);
				that.equipment(val, pageSize); // 获取设备列表数据
			},
			// 获取设备列表数据
			equipment: function (page, pageSize) {
				this.loading = true; //打开loading动画
				this.isLoad = false;
				var that = this;
				// ajax请求
				that.$post({
					url: 'Partner/Equipment/user_list',
					data: {
						page: page,
						pageSize: pageSize,
						equipment_number: that.equipment_number,
						start_time: that.start_time ? that.start_time : '',
						end_time: that.end_time ? that.end_time : '',
						name: that.name,
						tel: that.tel
					},
					success: data => {
						this.loading = false; //关闭动画
						this.isLoad = true;
						if (data.code == 1000) {
							that.tableData = []; // 清空数据
							$.each(data.data.order, function () {
								this.checked = false;
								that.tableData.push(this);
							});
							that.totalDataNumber = Number(data.data.count); // 总的数据
						} else {
							that.tableData = []; // 清空数据
						}
					}
				});
			},
			// 搜索事件
			serach: function () {
				var that = this;
				that.name = that.name;
				that.tel = that.tel;
				that.pageNo = 1; // 当前页
				locache.set('deviceListPage', that.pageNo);
				that.equipment(that.pageNo, that.pageSize); // 获取设备列表数据
			},
			reset() {
				var that = this;
				that.name = '';
				that.tel = '';
				that.start_time = '';
				that.end_time = '';
				that.pageNo = 1; // 当前页
				locache.set('deviceListPage', that.pageNo);
				that.equipment(that.pageNo, that.pageSize); // 获取设备列表数据
			}
		},
		mounted() { },
		watch: {}
	};
</script>

<style>
	#deviceuserlist {
		width: 100%;
		height: 100%;
		background: #ffffff;
	}
</style>